/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.model;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCStartup;

/**
 *
 * @author Natalie
 */
public class Ticket extends TicketComponent
{
    private String flightNum;
    private String username;
    private Flight f;
    private boolean booked = false;;

   
    public Ticket()
    {

    }

    public Ticket(String flightNum, String username)
    {
        this.flightNum = flightNum;
        this.username = username;
        getFlight();
        
    }

    public void getFlight()
    {
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(flightNum);
    }

    public int bookTicket(int bookingNum, int itemNum)
    {
        System.out.println("Ticket booked for:"+username + ". Flight: " + flightNum);
        MyDAO coms = UCStartup.getInstance().getDAO();
        booked = coms.sQLMakeBooking(this, bookingNum, itemNum);
        itemNum = itemNum +1;
        return itemNum;
    }

    public double getCost()
    {
        double cost = 0;
        //Get cost from flight table
        cost = Double.valueOf(f.getCost());
        return cost;
    }

    public double getGST()
    {
        double gst = getCost() * GSTax.getInstanceGSTax().getGST() / 100;

        
        return gst;

    }

    public double getAirportTax()
    {
        //Get departure location
        String depLoc = f.getDepLoc();
        MyDAO coms = UCStartup.getInstance().getDAO();
        double airportTax = coms.sQLGetAirportTax(f.getDepLoc());
        return airportTax;
    }

    /**
     * @return the gST
     */
   

    public void setFlightNum(String flightNum)
    {
        this.flightNum = flightNum;
    }

    public String getFlightNum()
    {
        return flightNum;
    }

    public void setUsername(String user)
    {
        username = user;
    }

    public String getUsername()
    {
        return username;
    }

    @Override
    public boolean containsFlight(String flightNum)
    {
        if( flightNum.equals(this.flightNum))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public boolean isBooked()
    {
        return booked;
    }
}
